home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
xscheme.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-01-20
|
32KB
|
879 lines
;;; xscheme.el --- run Scheme under Emacs
;; Copyright (C) 1986, 1987, 1989, 1990 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Keywords: languages, lisp
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; A major mode for editing Scheme and interacting with MIT's C-Scheme.
;;
;; Requires C-Scheme release 5 or later
;; Changes to Control-G handler require runtime version 13.85 or later
;;; Code:
(require 'scheme)
(defvar scheme-program-name "scheme"
"*Program invoked by the `run-scheme' command.")
(defvar scheme-band-name nil
"*Band loaded by the `run-scheme' command.")
(defvar scheme-program-arguments nil
"*Arguments passed to the Scheme program by the `run-scheme' command.")
(defvar xscheme-allow-pipelined-evaluation t
"If non-nil, an expression may be transmitted while another is evaluating.
Otherwise, attempting to evaluate an expression before the previous expression
has finished evaluating will signal an error.")
(defvar xscheme-startup-message
"This is the Scheme process buffer.
Type \\[advertised-xscheme-send-previous-expression] to evaluate the expression before point.
Type \\[xscheme-send-control-g-interrupt] to abort evaluation.
Type \\[describe-mode] for more information.
"
"String to insert into Scheme process buffer first time it is started.
Is processed with `substitute-command-keys' first.")
(defvar xscheme-signal-death-message nil
"If non-nil, causes a message to be generated when the Scheme process dies.")
(defun xscheme-evaluation-commands (keymap)
(define-key keymap "\e\C-x" 'xscheme-send-definition)
(define-key keymap "\C-x\C-e" 'advertised-xscheme-send-previous-expression)
(define-key keymap "\eo" 'xscheme-send-buffer)
(define-key keymap "\ez" 'xscheme-send-definition)
(define-key keymap "\e\C-m" 'xscheme-send-previous-expression)
(define-key keymap "\e\C-z" 'xscheme-send-region))
(defun xscheme-interrupt-commands (keymap)
(define-key keymap "\C-c\C-s" 'xscheme-select-process-buffer)
(define-key keymap "\C-c\C-b" 'xscheme-send-breakpoint-interrupt)
(define-key keymap "\C-c\C-c" 'xscheme-send-control-g-interrupt)
(define-key keymap "\C-c\C-u" 'xscheme-send-control-u-interrupt)
(define-key keymap "\C-c\C-x" 'xscheme-send-control-x-interrupt))
(xscheme-evaluation-commands scheme-mode-map)
(xscheme-interrupt-commands scheme-mode-map)
(defun run-scheme (command-line)
"Run MIT Scheme in an inferior process.
Output goes to the buffer `*scheme*'.
With argument, asks for a command line."
(interactive
(list (let ((default
(or xscheme-process-command-line
(xscheme-default-command-line))))
(if current-prefix-arg
(read-string "Run Scheme: " default)
default))))
(setq xscheme-process-command-line command-line)
(pop-to-buffer (xscheme-start-process command-line)))
(defun reset-scheme ()
"Reset the Scheme process."
(interactive)
(let ((process (get-process "scheme")))
(cond ((or (not process)
(not (eq (process-status process) 'run))
(yes-or-no-p
"The Scheme process is running, are you SURE you want to reset it? "))
(message "Resetting Scheme process...")
(if process (kill-process process t))
(xscheme-start-process xscheme-process-command-line)
(message "Resetting Scheme process...done")))))
(defun xscheme-default-command-line ()
(concat scheme-program-name " -emacs"
(if scheme-program-arguments
(concat " " scheme-program-arguments)
"")
(if scheme-band-name
(concat " -band " scheme-band-name)
"")))
;;;; Interaction Mode
(defun scheme-interaction-mode ()
"Major mode for interacting with the inferior Scheme process.
Like scheme-mode except that:
\\[advertised-xscheme-send-previous-expression] sends the expression before point to the Scheme process as input
\\[xscheme-yank-previous-send] yanks the expression most recently sent to Scheme
All output from the Scheme process is written in the Scheme process
buffer, which is initially named \"*scheme*\". The result of
evaluating a Scheme expression is also printed in the process buffer,
preceded by the string \";Value: \" to highlight it. If the process
buffer is not visible at that time, the value will also be displayed
in the minibuffer. If an error occurs, the process buffer will
automatically pop up to show you the error message.
While the Scheme process is running, the modelines of all buffers in
scheme-mode are modified to show the state of the process. The
possible states and their meanings are:
input waiting for input
run evaluating
gc garbage collecting
The process buffer's modeline contains additional information where
the buffer's name is normally displayed: the command interpreter level
and type.
Scheme maintains a stack of command interpreters. Every time an error
or breakpoint occurs, the current command interpreter is pushed on the
command interpreter stack, and a new command interpreter is started.
One example of why this is done is so that an error that occurs while
you are debugging another error will not destroy the state of the
initial error, allowing you to return to it after the second error has
been fixed.
The command interpreter level indicates how many interpreters are in
the command interpreter stack. It is initially set to one, and it is
incremented every time that stack is pushed, and decremented every
time it is popped. The following commands are useful for manipulating
the command interpreter stack:
\\[xscheme-send-breakpoint-interrupt] pushes the stack once
\\[xscheme-send-control-u-interrupt] pops the stack once
\\[xscheme-send-control-g-interrupt] pops everything off
\\[xscheme-send-control-x-interrupt] aborts evaluation, doesn't affect stack
Some possible command interpreter types and their meanings are:
[Evaluator] read-eval-print loop for evaluating expressions
[Debugger] single character commands for debugging errors
[Where] single character commands for examining environments
Starting with release 6.2 of Scheme, the latter two types of command
interpreters will change the major mode of the Scheme process buffer
to scheme-debugger-mode , in which the evaluation commands are
disabled, and the keys which normally self insert instead send
themselves to the Scheme process. The command character ? will list
the available commands.
For older releases of Scheme, the major mode will be be
scheme-interaction-mode , and the command characters must be sent as
if they were expressions.
Commands:
Delete converts tabs to spaces as it moves back.
Blank lines separate paragraphs. Semicolons start comments.
\\{scheme-interaction-mode-map}
Entry to this mode calls the value of scheme-interaction-mode-hook
with no args, if that value is non-nil.
Likewise with the value of scheme-mode-hook.
scheme-interaction-mode-hook is called after scheme-mode-hook."
(interactive)
(kill-all-local-variables)
(scheme-interaction-mode-initialize)
(scheme-mode-variables)
(make-local-variable 'xscheme-previous-send)
(run-hooks 'scheme-mode-hook 'scheme-interaction-mode-hook))
(defun scheme-interaction-mode-initialize ()
(use-local-map scheme-interaction-mode-map)
(setq major-mode 'scheme-interaction-mode)
(setq mode-name "Scheme Interaction"))
(defun scheme